package com.example.wzh.robotsdemo;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.Toast;

public class WelcomeActivity extends AppCompatActivity {
//    private static final String URL = "https://api.gizwits.com/app/devdata/B28BGK2FB3Ds4tuPPL4kBy/latest";
    private String [] list =  {"合肥体验馆会议室", "合肥体验馆办公室", "合肥体验馆家居","月星1层","月星3层","武汉样板间"};
    private int type;
    private String TAG = "WelcomeActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);

//        startMyServer();

        new AlertDialog.Builder(this)
                .setTitle("请选择房间")
                .setItems(list , new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        Toast.makeText(WelcomeActivity.this, "已选中" + list[i], Toast.LENGTH_SHORT).show();
                        //此处type = 0，1，2
                        type = i;
                        Log.e(TAG,"type===" + type);
                        new Handler().postDelayed(new Runnable(){
                            public void run() {
                                startMyServer();
                                Intent intent = new Intent(WelcomeActivity.this, MainActivity.class);
                                startActivity(intent);
                                finish();
                            }
                        }, 2000);
                    }
                })
                .show();

    }
    private void startMyServer() {
        Intent startIntent = new Intent(this, MyService.class);
        startIntent.putExtra("type", type);
        startService(startIntent);
    }


}
